<template>
  <div>
    <h2 class="van-doc-block__title">公司列表</h2>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getLists"
    >
      <van-card
        v-for="list in lists"
        :key="list.corpId"
        @click="toCardList(list.corpId)"
      >
        <template #price>
          <div>联系人：{{list.contacter}}</div>
        </template>
        <template #desc>
          <div>公司名称：{{list.corpName}}</div>
          <div>地址：{{list.postAddr}}</div>
          <div>银行名称：{{list.bankName}}</div>
        </template>
      </van-card>
    </van-list>
  </div>
</template>

<script>
  import {Toast} from "vant";

  export default {
    name: "enterpriseCarCard",
    data() {
      return {
        query: {
          pageNum: 1,
          pageSize: 10,
          name: '',
          status: 2
        },
        lists: [],
        loading: false,
        finished: false,
      };
    },
    created() {
    },
    methods: {
      toCardList(e) {
        this.$router.push({
          name: "enterpriseCarCardList",
          query: {
            cardId: e
          }
        });
      },
      getLists() {
        // 异步更新数据
        this.$Api.get("/api/corp/findCorpList", this.query).then(res => {
          if (res.data.code == 200) {
            if (res.data.data.result.length > 0) {
              this.lists.push(...res.data.data.result);
              this.query.pageNum++
            } else {
              this.finished = true;
            }
          } else {
            Toast(res.data.message);
          }
          // 加载状态结束
          this.loading = false;
          // 数据全部加载完成
          if (res.data.data.result.length < 10) {
            this.finished = true;
          }
        }).catch(err => {
        });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .van-doc-block__title {
    margin: 0;
    padding: 24px 16px 16px;
    color: #09f;
    font-weight: normal;
    font-size: 16px;
    line-height: 16px;
    text-align: center;
    border-bottom: 1px solid #09f;
  }

  .van-card {
    background-color: #fff;
  }

  .van-card {
    margin-top: 0;
    border-bottom: 8px solid #f5f5f5;
  }
</style>
